package com.beep.erp.model.transfer.pallet;

import com.beep.erp.common.base.BaseBean;
import com.beep.erp.common.bean.BizStorageLocationsListBean;
import com.beep.erp.common.bean.PalletGoodsBean;
import com.beep.erp.http.HttpExceptionHandle;
import com.beep.erp.http.HttpResultSubscriber;

import rx.schedulers.Schedulers;

/**
 * Created by Jolly on 2018/9/2.
 */

public class PalletGoodsPresenter extends PalletGoodsContract.Presenter {
    @Override
    public void getPalletGoodsDetail(String sign, String timeStamp, String stockId) {
        mRxManage.add(mModel.getPalletGoodsDetail(sign, timeStamp, stockId).unsubscribeOn(Schedulers.io()).subscribe(new HttpResultSubscriber<PalletGoodsBean>() {
            @Override
            public void onError(HttpExceptionHandle.ResponeThrowable e) {
                mView.hideLoading();
                mView.showMessage(e.ErrorInfo);
            }

            @Override
            public void onNext(PalletGoodsBean goodsDetailBean) {
                mView.hideLoading();
                mView.getPalletGoodsDetail(goodsDetailBean);
            }
        }));
    }

    @Override
    public void movePosition(String sign, String timeStamp, String userId, String barcodeId, String goodsId, String number, String storageLocationIdFront, String storageLocationIdAfter) {
        mView.showLoading();
        mRxManage.add(mModel.movePosition(sign, timeStamp, userId, barcodeId, goodsId, number, storageLocationIdFront, storageLocationIdAfter).unsubscribeOn(Schedulers.io()).subscribe(new HttpResultSubscriber<BaseBean>() {
            @Override
            public void onError(HttpExceptionHandle.ResponeThrowable e) {
                mView.hideLoading();
                mView.showMessage(e.ErrorInfo);
            }

            @Override
            public void onNext(BaseBean baseBean) {
                mView.hideLoading();
                mView.movePosition(baseBean);
            }
        }));
    }

    @Override
    public void getBizStorageLocationList(String sign, String timeStamp, String type) {
        mRxManage.add(mModel.getBizStorageLocationList(sign, timeStamp, type).unsubscribeOn(Schedulers.io()).subscribe(new HttpResultSubscriber<BizStorageLocationsListBean>() {
            @Override
            public void onError(HttpExceptionHandle.ResponeThrowable e) {
                mView.hideLoading();
                mView.showMessage(e.ErrorInfo);
            }

            @Override
            public void onNext(BizStorageLocationsListBean bizStorageLocationsListBean) {
                mView.hideLoading();
                mView.getBizStorageLocationList(bizStorageLocationsListBean);
            }
        }));
    }

    @Override
    public void saveEarlyStoge(String sign, String timeStamp, String barcode, String goodsCode, String number, String typeInfo, String userId, String manufactureDate, String storageLocationId) {
        mView.showLoading();
        mRxManage.add(mModel.saveEarlyStoge(sign, timeStamp, barcode, goodsCode, number, typeInfo, userId, manufactureDate, storageLocationId).unsubscribeOn(Schedulers.io()).subscribe(new HttpResultSubscriber<BaseBean>() {
            @Override
            public void onError(HttpExceptionHandle.ResponeThrowable e) {
                mView.hideLoading();
                mView.showMessage(e.ErrorInfo);
            }

            @Override
            public void onNext(BaseBean baseBean) {
                mView.hideLoading();
                mView.saveEarlyStoge(baseBean);
            }
        }));
    }

    @Override
    public void onStart() {
        mView.getDate();
    }

}
